<?php


namespace core\mod;


use core\event\EventMessage;
use core\Mod;
use core\model\SysMod;
use core\service\ModService;

class SysCommand extends Mod {

    public function eventMessage(EventMessage $event) {
        if ($event->getSender()->id !== 842421996) {
            return;
        }
        $message = trim($event->getMessage()->string());
        switch ($message) {
            case "/get_mod_enabled":
                $text = "=====激活的模组=====\n";
                $text .= implode("\n", array_merge((array)(new ModService())->getEnableMod(), (array)config('mods')));
                $event->getSender()->sendMessage($text);
                break;
            case "/add_mod":
                $splits = explode(" ", $message);
                if (count($splits) < 2) {
                    $event->getSender()->sendMessage("错误的格式！应为 /add_mod <模组类>");
                    break;
                }
                $mod = $splits[1];
                // 判断该模组是否存在
                if (!class_exists($mod) || strpos($mod, "core\\") !== false) {
                    $event->getSender()->sendMessage("未找到模组：{$mod}");
                    break;
                }
                if (!empty((new SysMod())->getByName($mod))) {
                    $event->getSender()->sendMessage("已经存在该模组：{$mod}，请勿重复添加！");
                    break;
                }
                (new ModService())->addMod($mod);
                $event->getSender()->sendMessage("模组：{$mod} 添加成功！");
                break;
            case "/mod.enable":
                break;
            case "/mod.disable":
                break;
        }
    }

}
